#include "TimeConversion.h"

// Convert Time From Hours, Minutes, Seconds, Milliseconds To Milliseconds
void ConvertTimeToMilliseconds(long& hours, long& minutes, long& seconds, long& milliseconds)
{
	// Hours To Minutes
	while ( hours - 1 >= 0 )
	{
		hours -= 1;
		minutes += 60;
	}

	// Minutes To Seconds
	while ( minutes - 1 >= 0 )
	{
		minutes -= 1;
		seconds += 60;
	}

	// Seconds To Milliseconds
	while ( seconds - 1 >= 0 )
	{
		seconds -= 1;
		milliseconds += 1000;
	}
}

// Convert Time From Milliseconds To Hours, Minutes, Seconds, Milliseconds
void ConvertTimeFromMilliseconds(long& hours, long& minutes, long& seconds, long& milliseconds)
{
	// Milliseconds To Seconds
	while ( milliseconds - 1000 >= 0 )
	{
		seconds += 1;
		milliseconds -= 1000;
	}

	// Seconds To Minutes
	while ( seconds - 60 >= 0 )
	{
		minutes += 1;
		seconds -= 60;
	}

	// Minutes To Hours
	while ( minutes - 60 >= 0 )
	{
		hours += 1;
		minutes -= 60;
	}
}

// Get Time In Milliseconds
long GetTimeInMilliseconds(const long hours, const long minutes, const long seconds, const long milliseconds)
{
	// Setup
	long temp_hours			= hours;
	long temp_minutes		= minutes;
	long temp_seconds		= seconds;
	long temp_milliseconds	= milliseconds;

	// Hours To Minutes
	while ( temp_hours - 1 >= 0 )
	{
		temp_hours -= 1;
		temp_minutes += 60;
	}

	// Minutes To Seconds
	while ( temp_minutes - 1 >= 0 )
	{
		temp_minutes -= 1;
		temp_seconds += 60;
	}

	// Seconds To Milliseconds
	while ( temp_seconds - 1 >= 0 )
	{
		temp_seconds -= 1;
		temp_milliseconds += 1000;
	}

	return temp_milliseconds;
}